package com.craney.XMLSocket
{
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.XMLSocket;
	
	public class TestSocket
	{
		
		private var xmlsock:XMLSocket = new XMLSocket();
		public function TestSocket()
		{

//			var xmlFormattedData:String = "I am Craney.\nIt is a very terriably cold winter.\nThe story started...\n"; 
			var xmlFormattedData:String = "Hello\nHi\n\HowAreYou\n"; 
//			var xmlFormattedData:String = "1234\n5678\n90\n"; 
//			var xmlFormattedData:String = "aaaa\nssss\nxxxx\n"; 

			try
			{
				xmlsock = new XMLSocket();
				xmlsock.connect("127.0.0.1", 8085);
				xmlsock.addEventListener(DataEvent.DATA, onData);
				xmlsock.addEventListener(Event.CONNECT, go);
//				xmlsock.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

//				xmlsock.writeObject(xmlFormattedData);
				trace("OK!");

				trace("JioJio......");
				
			}
			catch(e:Error)
			{
				trace(e.getStackTrace());
			}
			finally
			{
				trace("over!")
			}
		
		}
		
		private function go(event:Event):void
		{
			var xmlFormattedData:String = "Hello\nHi\n\HowAreYou\n"; 
			xmlsock.send(xmlFormattedData);
		}
		
		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("IOErrorEvent.IO_ERROR=" + event);			
		}
		
		private function onData(event:DataEvent):void
		{
		    trace("[" + event.type + "] " + event.data);
		}

	}
}